package com.daimakuai.config;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author happyonion.yangtao
 * @Title: SwaggerConfig
 * @ProjectName admin-behind
 * @PackageName com.daimakuai.config
 * @Description TODO
 * @date Create at 2018/12/5 23:12
 */

@Configuration
@EnableWebMvc
@EnableSwagger2
public class SwaggerConfig {

    public Docket myDocket(){
            Docket docket = new Docket(DocumentationType.SWAGGER_2);
            ApiInfo apiInfo = new ApiInfoBuilder()
                    .title("API接口文档")
                    .description("")
                    .contact(new Contact("","",""))
                    .version("1.0")
                    .build();
            docket.apiInfo(apiInfo);

            //设置只生成被Api这个注解注解过的Ctrl类中有ApiOperation注解的api接口的文档
            docket.select().apis(RequestHandlerSelectors.withClassAnnotation(Api.class)).apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).build();

            return docket;
    }

}
